"""
生成随机日期或随机时间
"""
import os
import sys

path = os.path.dirname(__file__)
sys.path.append(os.path.join(path, ".."))

import time
import random


def gen_random_time():
    start = time.mktime((2021, 1, 1, 0, 0, 0, 0, 0, 0))
    end = float(int(time.time()))
    t = random.randint(start, end)
    date_tuple = time.localtime(t)
    date = time.strftime('%Y-%m-%d %H:%M:%S', date_tuple)
    return {
        'year': date_tuple.tm_year,
        'mon': date_tuple.tm_mon,
        'day': date_tuple.tm_mday,
        'hour': date_tuple.tm_hour,
        'min': date_tuple.tm_min,
        'sec': date_tuple.tm_sec,
        'time': t,
        'date': date
    }


if __name__ == '__main__':
    print(gen_random_time())
